<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Brain.js XOR Demo</title>
  </head>

  <body>
    <!-- 引入 Brain.js 库 -->
    <script src="https://cdn.jsdelivr.net/npm/brain.js"></script>
    <script>
      const data = [
        { input: "喜欢吃茄子么", output: "不喜欢" },
        // { input: "喜欢吃蒜么", output: "不喜欢" },
        { input: "喜欢吃榴莲么", output: "喜欢" },
        // { input: "喜欢打篮球么", output: "喜欢" },
        { input: "喜欢吃香蕉么", output: "不一定" },
        // { input: "喜欢吃菠萝么", output: "不一定" },
      ];

      const net = new brain.recurrent.LSTM();

      // 训练数据集
      // net.train(["Hello there", "How are you?", "Hello world", "Good morning"]);
      net.train(data, {
        iterations: 2500, // 迭代次数
        log: true, // 是否打印训练日志
        logPeriod: 100, // 每多少次迭代打印一次日志
      });

      // 测试模型
      // const output = net.run("Hello");
      // console.log(`Predicted continuation: ${output}`);
      const output = net.run("喜欢吃蒜茄子么");
      const output2 = net.run("喜欢吃着榴莲打篮球么");
      const output3 = net.run("喜欢吃着蒜茄子打篮球么");
      const output4 = net.run("喜欢吃苹果么");

      console.log("提问：喜欢吃蒜茄子么？");
      console.log(output); // 输出可能是 "frontend"
      console.log("提问：喜欢吃着榴莲打篮球么？");
      console.log(output2); // 输出可能是 "frontend"
      console.log("提问：喜欢吃着蒜茄子打篮球么？");
      console.log(output3); // 输出可能是 "frontend"
      console.log("提问：喜欢吃苹果么？");
      console.log(output3); // 输出可能是 "frontend"
    </script>
  </body>
</html>
